﻿@using Fyp.Models;

@{
    ViewBag.Title = "MeetingScheduler";
}
@{
    Layout = "~/Shared/_layoutPage.cshtml";
    var PageTitle = "Meeting Scheduler";

    try
    {
        if (Request["status"] == "logout")
        {
            WebSecurity.Logout();
            Response.Redirect("/Account/Login");
        }
    }
    catch (Exception e)
    {
        throw new System.Security.SecurityException("Logout...", e);
    }

    MeetingScheduler ms = new MeetingScheduler();
    Group g = new Group();
    Project p = new Project();


    var UserName = ViewData["username"]; 
    var MeetingTitle = ViewData["meetingtitle"];
    var MeetingLocation = ViewData["meetinglocation"];
    var Guests = ViewData["guests"];
    var MeetingDate = ViewData["meetingdate"];
    var StartTime = ViewData["starttime"];
    var EndTime = ViewData["endtime"];
    var Description = ViewData["description"];
    var Comment = ViewData["comment"];
    var Gid = ViewData["gid"];
    var MeetingType = ViewData["meetingtype"];
    var Reminder = ViewData["reminder"];
    var UserId = ViewData["userid"];
    
    var ProjectTitle = ViewData["projtitle"];

    var MeetingTitle2 = ms.MeetingTitle;
    var MeetingLocation2 = ms.MeetingLocation;
    var Guests2 = ms.Guests;
    var MeetingDate2 = ""; ;
    var StartTime2 = ms.StartTime;
    var EndTime2 = ms.EndTime;
    var Description2 = ms.DescriptionText;
    var Gid2 = ms.GId;
    var MeetingType2 = ms.MeetingType;
    var Reminder2 = ms.Reminder;
    var Comment2 = ms.CommentText;
    var AdvisorId2 = ms.UserId;

    var mid = 0;

    var meeting = (List<MeetingScheduler>)ViewData["data"];
    var group = (List<Group>)ViewData["grp"];
    var projTitle = (List<String>)ViewData["projecttitle"];

    var meetingTypeDD = new List<string>();
    meetingTypeDD.Add("--Select--");
    meetingTypeDD.Add("Proposed");
    meetingTypeDD.Add("Confirmed");

    var ReminderDD = new List<string>();
    ReminderDD.Add("--Select--");
    ReminderDD.Add("1 day before");
    ReminderDD.Add("2 days before");
    ReminderDD.Add("3 days before");
    ReminderDD.Add("4 days before");
    ReminderDD.Add("5 days before");
    ReminderDD.Add("6 days before");
    ReminderDD.Add("1 week before");
    ReminderDD.Add("2 week before");
    ReminderDD.Add("None");


    var gid = 0;

    if (meeting != null)
    {
        foreach (var data in meeting)
        {
            MeetingTitle2 = data.MeetingTitle;
            MeetingLocation2 = data.MeetingLocation;
            Guests2 = data.Guests;
            MeetingDate2 = data.MeetingDate.Value.ToString("dd/MM/yyyy"); ;
            StartTime2 = data.StartTime;
            EndTime2 = data.EndTime;
            Description2 = data.DescriptionText;
            Comment2 = data.CommentText;
            Gid2 = data.GId;
            MeetingType2 = data.MeetingType;
            Reminder2 = data.Reminder;
            AdvisorId2 = data.UserId;

            mid = Convert.ToInt32(data.MeetingId);
        }
        foreach (var item in meeting)
        {
            ms = item;
        }
    }

    if (group != null)
    {
        foreach (var data in group)
        {
            gid = Convert.ToInt32(data.GId);
        }
        foreach (var item in group)
        {
            g = item;
        }
    }
   
    var grpandtitle = group.Zip(projTitle, (gro, pro) => new { grp = gro, proj = pro });
    var meetingdate = "";
    if(ms.MeetingDate!=null)
    {
        meetingdate = ((DateTime)ms.MeetingDate).ToString("dd/MM/yyyy");
    }
   

}


@section title
{
    @PageTitle
}

<script src="/Scripts/jquery-1.8.2.js" type="text/javascript"></script>
<link rel="stylesheet" href="/Styles/form.css" />
<script src="/Scripts/jquery-ui.js" type="text/javascript"></script>
<link rel="stylesheet" href="/Styles/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="~/Styles/template.css" media="screen">
<link href="../../Styles/jquery.ambiance.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/jquery.ambiance.js" type="text/javascript"></script>
<link rel="stylesheet" href="/Styles/jquery.timeentry.css" />
<script type="text/javascript" src="/Scripts/jquery.timeentry.js"></script>

<script type="text/javascript">

    function Send() {
        $.ambiance({
            message: "Your notification is sent successfully!",
            title: "Success!",
            type: "success"
        });
    }

    function Cancel() {


        $.ambiance({
            message: "Cancel Notification!",
            type: "error",
            fade: false
        });
    }

    //$(document).ready(function () {
    //    $("#mdate1").datepicker({
    //        changeMonth: true,
    //        changeYear: true,

    //        beforeShow: function (input, inst)
    //        { inst.dpDiv = $('<div style="display: none;"></div>'); }
    //    });


    //    $("#mdate").datepicker({
    //        changeMonth: true,
    //        changeYear: true,
    //    });

    //    $("#starttime").timeEntry({ show24Hours: false, showSeconds: false, ampmNames: ['AM', 'PM'] });

    //    $("#starttime1").timeEntry({

    //        starttime1: readonly(),
    //        show24Hours: false, showSeconds: false, ampmNames: ['AM', 'PM'],

    //    });

    //    $("#endtime").timeEntry({ show24Hours: false, showSeconds: false, ampmNames: ['AM', 'PM'] });

    //    $("#endtime1").timeEntry({

    //        endtime1: readonly(),
    //        show24Hours: false, showSeconds: false, ampmNames: ['AM', 'PM'],

    //    });


    //});

</script>

@using (Html.BeginForm("MeetingScheduler", "MeetingScheduler", FormMethod.Post, new { @class = "background" }))
{
    <strong>
       <br/> 
        <div id="content">
                <h2 style="text-align: center;margin-left: 192px;width: 504px;margin-bottom: -43px;"><b>Meeting Scheduler</b></h2>
         </div>
    </strong>
   
    <table style="margin-left: 23px;">
        <tbody>
            <tr>
               <input type="text" name= "ID" class ="clear" style="display:none" value = "@mid" />

                 @if (WebSecurity.IsAuthenticated && Roles.IsUserInRole("Advisor"))
                 {
                      <td> Meeting Title:</td>
                     
                     if (ms.MeetingId == null || ms.MeetingId == 0)
                     {
                        <td>
                                <input type="text" name="mtitle" value ="@MeetingTitle"  required/>
                        </td>
                     }
                     else
                     {
                         <td>
                                <input type="text" name="mtitle" value ="@MeetingTitle2" required  />
                        </td>
                     }
                 }
                 else
                 {
                     <td>
                            <label style="margin-left: 191px;">Meeting Title:&nbsp;@ms.MeetingTitle</label>
                            <input type="hidden" name="mtitle" value ="@ms.MeetingTitle"   /> 
                     </td>
                 }
                

                 @if (WebSecurity.IsAuthenticated && Roles.IsUserInRole("Advisor"))
                 {
                     <td>Meeting Type:</td>
                     if (ms.MeetingId == null || ms.MeetingId == 0)
                     {
                        <td>
                            <select name ="mtype" value ="@MeetingType2" required>
                                   @foreach (var item in meetingTypeDD)
                                   {
                                       if (item == MeetingType2)
                                       {
                                            
                                             <option value="@item" selected="selected" >@item</option>
                                       }
                                       else
                                       {
                                             <option value="@item">@item</option>
                                       }
                                   }
                             </select>
                        </td>
                     }
                     else
                     {
                          <td>
                            <select name ="mtype" value ="@MeetingType2"  required>
                                   @foreach (var item in meetingTypeDD)
                                   {
                                       if (item == MeetingType2)
                                       {
                                           <option value="@item" selected="selected">@item</option>
                                       }
                                       else
                                       {
                                             <option value="@item">@item</option>
                                       }
                                   }
                             </select>
                         </td>
                     }
                 }
                 else
                 {
                      <td>
                            <label style="margin-left: 130px;">Meeting Type:&nbsp;@ms.MeetingType</label>
                            <input type="hidden" name="mtype" value ="@ms.MeetingType"   /> 
                      </td>
                 }
            </tr>
               
               <tr>
                
                @if (WebSecurity.IsAuthenticated && Roles.IsUserInRole("Advisor"))
                {
                     <td>Meeting Location:</td>
                    
                    if (ms.MeetingId == null || ms.MeetingId == 0)
                    {
                        <td>
                                <input type="text" name="mlocation" value="@MeetingLocation" required />
                        </td>
                    }
                    else
                    {
                        <td>
                                <input type="text" name="mlocation" value="@MeetingLocation2" required/>
                        </td>
                    }
                }
                else
                {
                     <td>
                            <label style="margin-left: 191px;">Meeting Location:&nbsp;@ms.MeetingLocation</label>
                            <input type="hidden" name="mlocation" value="@ms.MeetingLocation" />
                      </td>             
                }
                
                

                 @if (WebSecurity.IsAuthenticated && Roles.IsUserInRole("Advisor"))
                 {
                     <td>Guests:</td>
                     if (ms.MeetingId == null || ms.MeetingId == 0)
                     {
                        <td>
                             <input type="text" name="mguests" value="@Guests" required />
                        </td>
                     }
                     else
                     {
                         <td>
                             <input type="text" name="mguests" value="@Guests2" required />
                        </td>
                     }
                 }
                 else
                 {
                      <td>
                            <label style="margin-left: 132px;">Guests:&nbsp;@ms.Guests</label>
                            <input type="hidden" name="mguests" value="@ms.Guests" />
                      </td>
                 }
            </tr>
              
              <tr>

                 @if (WebSecurity.IsAuthenticated && Roles.IsUserInRole("Advisor"))
                 {
                     <td>Meeting Date:</td>
                     if (ms.MeetingId == null || ms.MeetingId == 0)
                     {
                        <td>
                               <input type="date" name="mdate" value="@MeetingDate" required />
                        </td>
                     }
                     else
                     {
                        <td>
                               <input type="date" name="mdate"  value="@meetingdate" required />
                        </td>
                     }
                 }
                 else
                 {
                     <td>
                            <label style="margin-left: 191px;">Meeting Date:&nbsp;@meetingdate</label>
                            <input type="hidden" name="mdate"  value="@meetingdate" />
                     </td>
                 }
               

               @if (WebSecurity.IsAuthenticated && Roles.IsUserInRole("Advisor"))
               {
                    <td style="margin-left: 132px;">FYP'S: </td>
                   if (ms.MeetingId == null || ms.MeetingId == 0)
                   {
                        <td>
                              <select name ="grp">  
                                  <option>--Select--</option>
                                   @foreach (var data in grpandtitle)
                                   {
                                       <option value ="@data.grp.GId">@data.proj</option>
                                   } 
                               </select>
                        </td>
                   }
                   else
                   {
                         <td>
                            <select name ="grp" >
                                 @foreach (var data in grpandtitle)
                                 {
                                     <option value ="@data.grp.GId">@data.proj</option>     
                                 } 
                            </select>
                        </td>
                   }
               }
               else
               {
                  <td>
                      <td>
                          <label  style="margin-left: -172px;">FYP's:&nbsp;@ProjectTitle</label>
                           <input type="hidden" name ="grp"  value="@ProjectTitle" />
                     </td>
                  </td>
               }
            </tr>
                   <tr>

                        @if (WebSecurity.IsAuthenticated && Roles.IsUserInRole("Advisor"))
                        {
                             <td>Start Time:</td>
                            if (ms.MeetingId == null || ms.MeetingId == 0)
                            {
                                <td>
                                    <input type="time" name="starttime"  value="@StartTime" required/>
                                </td>
                            }
                            else
                            {
                                 <td>
                                    <input type="time" name="starttime" value="@StartTime2" required/>
                                </td>
                            }
                        }
                        else
                        {
                            <td>
                               <label   style="margin-left: 191px;">Start Time:&nbsp;@ms.StartTime</label>
                                <input type="hidden" name="starttime" value="@ms.StartTime" />
                            </td>
                        }
                       
                       @if (WebSecurity.IsAuthenticated && Roles.IsUserInRole("Advisor"))
                       {
                             <td>
                                End Time:
                             </td>
                           
                           if (ms.MeetingId == null || ms.MeetingId == 0)
                           {
                                <td>
                                    <input type="time" name="endtime"   value="@EndTime" required/>
                                </td>
                           }
                           else
                           {
                               <td>
                                    <input type="time" name="endtime"  value="@EndTime2" required />
                                </td>
                           }
                       }
                       else
                       {
                            <td>
                                 <label  style="margin-left: 132px;">End Time:&nbsp;@ms.EndTime</label>
                                 <input type="hidden" name="endtime"  value="@ms.EndTime" />
                            </td>
                       }
                </tr>
                
                   <tr>
                        

                        @if (WebSecurity.IsAuthenticated && Roles.IsUserInRole("Advisor"))
                        {
                            <td>
                                Reminder:
                            </td>
                            
                            if (ms.MeetingId == null || ms.MeetingId == 0)
                            {
                                <td>
                                     <select name="reminder" value="@Reminder" required>
                                       
                                    @foreach (var item in ReminderDD)
                                    {
                                        if (item == Reminder2)
                                        {
                                          <option value="@item" selected="selected">@item</option>
                                        }
                                        else
                                        {
                                          <option value="@item">@item</option>
                                        }
                                    }
                                    </select>
                                </td>
                            }
                            else
                            {
                                <td>
                                <select name="reminder" value="@Reminder2" required>
                                    

                                   @foreach (var item in ReminderDD)
                                   {
                                       if (item == Reminder2)
                                       { 
                                           <option value="@item" selected="selected">@item</option>
                                       }
                                       else
                                       {
                                           <option value="@item">@item</option>
                                       }
                                   }
                                  </select>
                                </td>
                            }
                        }
                        else
                        {
                          <td>
                            <label style="margin-left: 191px;">Reminder:&nbsp;@ms.Reminder</label>
                             <input type="hidden"  name="reminder"  value="@ms.Reminder"/>
                          </td>
                        }
                       
                </tr>

            <tr>

                <tr>

                     @if (WebSecurity.IsAuthenticated && Roles.IsUserInRole("Advisor"))
                     {
                          <td>Description:</td>
                         
                         if (ms.MeetingId == null || ms.MeetingId == 0)
                         {
                                <td><textarea name="description" id="description" rows="8" cols="40" required  >@Description</textarea></td>
                         }
                         else
                         {
                               <td><textarea name="description" id="description" rows="8" cols="40" required >@Description2</textarea></td>
                         }
                     }
                     else
                     {
                         <td>
                            <label style="margin-left: 191px;">Description:&nbsp;@ms.DescriptionText</label>
                             <input type="hidden"  name="description"   value="@ms.DescriptionText"/>
                         </td> 
                     }
                </tr>
                
                <tr>
                     @if (WebSecurity.IsAuthenticated && Roles.IsUserInRole("Advisor"))
                     {
                         if ((ms.MeetingId == null || ms.MeetingId == 0) && (Comment2 != "" || Comment2 != null))
                         {
                            <td> <textarea name="comment" id="comment" rows="4" cols="25" style="display:none">@Comment</textarea></td>
                         }
                         else
                         {
                             <td>Comment:</td><td> <textarea name="comment" id="comment" rows="4" cols="25" readonly="readonly" >@Comment2</textarea></td>   
                         }
                     }
                     else
                     {
                         if (MeetingType2 == "Proposed")
                         {
                              <td><label  style="margin-left:192px;">Comment:</label></td><td> <textarea name="comment" id="comment" rows="4" cols="25" style="display:block;margin-left:-182px;" required>@Comment2</textarea></td>
                         }
                     }
                </tr>

                 <tr>
                    @if (WebSecurity.IsAuthenticated && Roles.IsUserInRole("Advisor"))
                    {


                        if ((ms.MeetingId == null || ms.MeetingId == 0))
                        {
                            <td><label>Students: </label>@ms.UserId</td>
                        }
                        else
                        {
                           <td><label>Students: </label>@ms.UserId</td>
                        }
                    }
                </tr>
                
            
                <tr>
                    <td></td>

                     @if (WebSecurity.IsAuthenticated && Roles.IsUserInRole("Advisor"))
                     {
                         <td>
                         <input type="submit" style="display:block" value="Send"  class ="buttonSave" onclick="Send()" />
                         <input type="submit" style="display:block; margin-left: 87px;margin-top: -37px;" value="Cancel" class ="buttonCancel" onclick="Edit()" />
                         </td>
                     }
                     else
                     {
                          <td>
                         <input type="submit" value="Send" style="display:none"  class ="buttonSave" onclick="Send()" />
                         <input type="submit" value="Cancel" style="display:none" class ="buttonCancel" onclick="Edit()" />
                         </td>
                     }
                </tr>

             <tr>
                    <td></td>

                     @if (WebSecurity.IsAuthenticated && Roles.IsUserInRole("Advisor"))
                     {
                         <td>
                         <input type="submit" style="display:none" value="Send"  class ="buttonSave" onclick="Send()" />
                         </td>
                     }
                     else
                     {
                          <td>
                          @if (MeetingType2 == "Proposed")
                          {
                              <input type="submit" value="Send" style="display:block; margin-left: 51px;margin-top: -50px;"  class ="buttonSave" onclick="Send()" />
                          }
                         </td>
                     }
                </tr>
        </tbody>
    </table>
    
}